// class Edit{
//    constructor(){
//       this.editShop();
//    }
function editShop(){
      var btnEdit = document.querySelectorAll('.btn-edit');
      Array.from(btnEdit).forEach(function(edit){
         edit.onclick = function(){
            var tr = this.parentNode.parentNode;
            tr.classList.add('edit');
            var spans = tr.querySelectorAll('span');
            for(var i=0;i<spans.length;i++){
               spans[i].nextSibling.value = spans[i].innerHTML;
            }
         }
      })
   }
//editShop();

function ok(){
   var btnOk = document.querySelectorAll('.btn-ok');
   Array.from(btnOk).forEach(function(ok){
       ok.onclick = function(){
           var tr = this.parentNode.parentNode;
           var id = tr.children[0].innerHTML;
           var name = tr.children[1].children[1].value;
           var price = tr.children[2].children[1].value;
           var num = tr.children[3].children[1].value;
           tr.children[1].children[0].innerHTML = name;
           tr.children[2].children[0].innerHTML = price;
           tr.children[3].children[0].innerHTML = num;
           tools.fetch('api/v1/shop/edit',{id,name,price,num});
           this.parentNode.parentNode.classList.remove('edit');
       }
   })
}

function cancel(){
   var cancels = document.querySelectorAll('.btn-cancel');
   Array.from(cancels).forEach(function(cancel){
       cancel.onclick = function(){
           this.parentNode.parentNode.classList.remove('edit');
       }
   })
}

$('#tbody-list').on('click','.btn-del',function(){
   if(confirm('请确认删除!')){
      const  id =$(this).parents('tr').attr('data-id')
      $.get('/api/v1/shop/delete',{ id },resp=>{
         if(resp.code===200){
            console.log(resp)
            sel.getData()
            // $(this).parents('tr').remove()
         }
      })
   }
})